<?php

class HistoricoSituacaoDao extends Dao {

    public function injectDependencies() {

    }

    public function findByCustomer($IDCliente) {
        $this->initTransaction();
        $this->tMysqli->escape($IDCliente);
        $StSql = TQuery::getSqlFindSituationHistoryByCustomer($IDCliente);
        $tQuery = $this->tMysqli->exec($StSql);
        $ArHistoricoSituacao = array();
        while($ArHistoricoData = mysqli_fetch_assoc($tQuery)) {
            $ArHistoricoSituacao[] = new HistoricoSituacao($ArHistoricoData, $this->tMysqli);
        }
        $this->closeTransaction();
        return $ArHistoricoSituacao;
    }

    public function findDeliquentsCustomers() {
        $this->initTransaction();
        $StSql = TQuery::getSqlFindAllDelinquentsCustomers();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArDelinquents = array();
        while($ArIdClientes = mysqli_fetch_assoc($tQuery)) {
            $ArDelinquents[] = $ArIdClientes['IDCliente'];
        }
        $this->closeTransaction();
        return $ArDelinquents;
    }

    public function getHeadLineSituationFor($EnStatus) {
        $this->initConnection();
        $this->tMysqli->escape($EnStatus);
        $StSql = TQuery::getSqlFindSituationByStatusOrderDesc($EnStatus);
        $this->tMysqli->exec($StSql);
        $ArSituationTimes = $this->tMysqli->result(0);
        $this->closeConnection();
        return $ArSituationTimes;
    }

    public function findPunctualCustomers() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindPuctualCustomers();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArCustomers = array();
        while($ArCustomersData = mysqli_fetch_assoc($tQuery)) {
            $ArCustomers[] = new Cliente($ArCustomersData['IDCliente'], $ArCustomersData, $this->tMysqli);
        }
        $this->closeConnection();
        return $ArCustomers;
    }

}

?>
